import pandas as pd

df = pd.read_excel('../output/合成表.xlsx')
df.fillna(0, inplace=True)
cysc = list(df['持有时长'].astype(int))
syl = list(df['收益率'])
trq = [0] * len(cysc)  # 投入前
tre = [0] * len(cysc)  # 投入额
trh = [0] * len(cysc)  # 投入后
dq = [0] * len(cysc)  # 每次投资到期总额
dqe = [0] * len(cysc)  # 每天到期总额
zc = [0] * len(cysc)  # 实时资产
tr = 0.5  # 投入比例


def mn_tz():
    trq[0] = 707.11
    if cysc[0] != 0:
        tre[0] = trq[0] * tr
    else:
        tre[0] = 0
    trh[0] = trq[0] - tre[0]
    dq[0] = int(100 * tre[0] * (syl[0] / 100 + 1)) / 100
    dqe[cysc[0]] += dq[0]
    zc[0] = 707.11
    for i in range(1, len(cysc)):
        trq[i] = trh[i - 1] + dqe[i]
        if cysc[i] != 0:
            tre[i] = trq[i] * tr
        else:
            tre[i] = 0
        trh[i] = trq[i] - tre[i]
        dq[i] = int(100 * tre[i] * (syl[i] / 100 + 1)) / 100
        dqe[i + cysc[i]] += dq[i]
        zc[i] = 707.11 - sum(tre[:i + 1]) + sum(dq[:i + 1])


mn_tz()
print(zc[-1])
df['投入前'] = trq
df['投入额'] = tre
df['投入后'] = trh
df['到期总额'] = dq
df['到期额'] = dqe
df['资产'] = zc
print(df)
df.to_excel('../output/模拟投资.xlsx', index=False)
